package com.itheima.hash;

import java.util.HashSet;

public class Demo01 {
    public static void main(String[] args) {
        HashSet<Student1> hashSet = new HashSet<>();
        hashSet.add(new Student1("zs",18));
        hashSet.add(new Student1("zs",18));
        hashSet.add(new Student1("ls",19));

        System.out.println(hashSet);
    }
}
class Student1 {
    private String name;
    private Integer age;

    public Student1() {
    }

    public Student1(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student1 student1 = (Student1) o;

        if (name != null ? !name.equals(student1.name) : student1.name != null) return false;
        return age != null ? age.equals(student1.age) : student1.age == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (age != null ? age.hashCode() : 0);
        return result;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

}
